﻿#region 命名空间

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model;
using WinnerCMS.Model.Attribute;

#endregion

namespace WinnerCMS.WebUI.Admin.UDT
{
    [Access("262001,262003")]
    public partial class JS : WebFactory.PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.lblPath.Text = "<a href='UDT_Manage.aspx'>标签管理</a> → 静态JS标签";
                if (Request["ID"] != null)
                {
                    //“修改”界面
                    Edit_Load();
                }
            }
        }

        #region 加载

        private void Edit_Load()
        {
            var model = new UDTManage().GetInfo(Request["ID"]);
            if (model != null)
            {
                this.txtName.Text = model.Name;
                this.txtRemark.Text = model.Remark;
                this.txtTag.Text = model.Tag;
                this.txtJsPath.Text = model.JsPath;

                Title = "修改" + model.Name;
            }
            else
            {
                //转向错误页面
                ErrClass.Redirect("数据不存在。");
            }
        }

        #endregion

        protected void btnOK_Click(object sender, EventArgs e)
        {
            var model = new WinnerCMS.Model.UDT
            {
                Name = this.txtName.Text.Trim(),
                DataSource = "",
                SqlScript = "",
                Type = 3,
                JsPath = this.txtJsPath.Text.Trim(),
                URLType = "4",
                ItemTemplate = "",
                EmptyDataTemplate = "",
                Remark = this.txtRemark.Text.Trim(),
                Tag = this.txtTag.Text.Trim()
            };


            if (Request["ID"] == null)
            {
                model.Id = 0;
            }
            else
            {
                model.Id = int.Parse(Request["ID"]);
            }
            var res = new UDTManage().Add(model);

            if (string.IsNullOrEmpty(res.Errors) != true)
            {
                MsgBox.Message(res.Errors, this.UpdatePanel1);
            }
            else
            {
                MsgBox.Message("录入成功！", this.UpdatePanel1);
            }
        }
    }
}